<template>
  <d2-container>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <div class="d2-breadcrumb">
        <el-breadcrumb-item>编辑角色</el-breadcrumb-item>
      </div>
    </el-breadcrumb>
    <el-form label-width="150px" :model="query" :rules="rules" ref="add">
      <el-form-item label="角色名称" prop="roleName">
        <el-input v-model="query.roleName" style="width: 240px"></el-input>
      </el-form-item>
      <el-form-item label="角色权限" prop="roleKey">
        <el-input v-model="query.roleKey" style="width: 240px"></el-input>
      </el-form-item>
      <el-form-item label="显示顺序" prop="roleSort">
        <el-input v-model="query.roleSort" style="width: 240px"></el-input>
      </el-form-item>
      <el-form-item label="账号状态" prop="status">
        <el-select v-model="query.status" placeholder="请选择" style="width: 240px">
          <el-option label="正常" value="0"></el-option>
          <el-option label="停用" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="add">编辑</el-button>
      </el-form-item>
    </el-form>
  </d2-container>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      id: this.$route.params.id,
      query: {},
      rules: {},
    };
  },
  methods: {
    add() {
      this.$refs["add"].validate((valid) => {
        if (valid) {
          let params = {
            ...this.query,
          };
          console.log("提交内容：", params);
          this.$axios.post("/sysRole/update", params).then((result) => {
            console.log("响应", result);
            if (result.code == 200) {
              this.$message.success("操作成功");
              this.$router.push("/systemAdmin/role");
              this.$refs["add"].resetFields();
            } else {
              this.$message.error(result.data.msg);
            }
          });
        } else {
          return false;
        }
      });
    },
    getInfo() {
      this.$axios
        .post("/sysRole/getOneRole", { roleId: this.id })
        .then((result) => {
          if (result) {
            this.query = {
              ...result.data,
            };
          } else {
            this.$message.error(result.data.msg);
          }
        });
    },
  },
  created() {
    this.getInfo();
  },
};
</script>

<style scoped lang="scss">
.item-box {
  position: relative;
  width: 30%;
  .item-delete {
    position: absolute;
    right: 80px;
    top: -45px;
  }
}
.card-box {
  display: flex;
  flex-wrap: wrap;
}
</style>
